package com.qdaily.ui.ui.jpush;

import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 推送过来的对象
 * Created with IntelliJ IDEA.
 * User: Felix
 * Date: 5/14/15
 * Time: 18:11
 * QQ:74104
 * Email:lovejiuwei@gmail.com
 */
public class JpushObj implements Parcelable {
    private int genre = 0;
    private int id = 0;

    private final String KEY_GENRE = "genre";
    private final String KEY_MESSAGE_ID = "message_id";

    public JpushObj(String extra) {
        phaseJason(extra);
    }

    private void phaseJason(String extra) {
        JSONObject json = null;
        try {
            json = new JSONObject(extra);
            if (json != null) {
                setGenre(json.optInt(KEY_GENRE));
                setId(json.optInt(KEY_MESSAGE_ID));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public int getGenre() {
        return genre;
    }

    public void setGenre(int genre) {
        this.genre = genre;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.genre);
        dest.writeInt(this.id);
    }

    private JpushObj(Parcel in) {
        this.genre = in.readInt();
        this.id = in.readInt();
    }

    public static final Parcelable.Creator<JpushObj> CREATOR = new Parcelable.Creator<JpushObj>() {
        public JpushObj createFromParcel(Parcel source) {
            return new JpushObj(source);
        }

        public JpushObj[] newArray(int size) {
            return new JpushObj[size];
        }
    };
}
